#ifndef HARDINTERFACETEST_H
#define HARDINTERFACETEST_H

#include <QWidget>
#include "jwidget/jdialog.h"
#include <QDialog>
#include "weiqiantools/serialport.h"
#include "weiqiantools/weiqianfunctions.h"
#include "weiqiantools/serialportreadthread.h"
#include "InputMethod/inputmethod.h"

extern "C"
{
	#include <sys/types.h>
	#include <sys/stat.h>
	#include <unistd.h>
	#include <stdio.h>
	#include <netinet/in.h>
	#include <netinet/ip.h>
	#include <netinet/ip_icmp.h>
	#include <unistd.h>
	#include <signal.h>
	#include <arpa/inet.h>
	#include <errno.h>
	#include <sys/time.h>
	#include <string.h>	
	#include <netdb.h>
	#include <pthread.h>
	#include <sys/ioctl.h>
	#include <net/if.h>
	#include <net/route.h>
}





typedef struct ping_packet_status
{
    struct timeval begin_time;
    struct timeval end_time;
    int flag;   //发送标志,1为已发送
    int seq;     //包的序列号
}ping_packet_status;





QT_BEGIN_NAMESPACE
class QLineEdit;
class QCheckBox;
QT_END_NAMESPACE
static int canSuccessFlag;
static int yejingpingSuccessFlag;
static int louguangSuccessFlag;
static int beefSuccessFlag;
static int beiguangSuccessFlag;
static int chumoSuccessFlag;
static int tmpitem;
static int louguangflagtu;
static int caltouchFlag;

static int receive1;
static int receive2;
static int receive3;
static int receive4;
static int flag485;
static int wifiorwangka;
static int wangkarate;
static int wifikarate;
static int wifikacount;
static int wangkacount;
static QString wangkaiptmp;
static QString wifikaiptmp;

class PleasWait : public QDialog
{
    Q_OBJECT
 public:
    PleasWait(QWidget *parent = 0);
   ~PleasWait();
    int wifilianflag;
    int flagcount;
private:
    QLabel*giflabel;
    QLabel*giflabelt;
    QTimer*timer66;
    QPushButton *forceclose;
private slots:
    void gifwait();

};

class Chumohuaban : public QDialog
{
    Q_OBJECT

public:
    Chumohuaban(QWidget *parent = 0);
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    int xx;
    int yy;
    QPoint startPos;
    ~Chumohuaban();

protected:
    void paintEvent(QPaintEvent *event);
};
/*
Chumohuaban::Chumohuaban(QWidget *parent) : QDialog(parent)
{
    resize(int_WIDGET_W,int_WIDGET_H);
    xx=0;
    yy=0;
    this->setWindowFlags(Qt::FramelessWindowHint);
    this->exec();
}

void Chumohuaban::mousePressEvent(QMouseEvent *event)
{
    xx=event->pos().x();
    yy=event->pos().y();
     update();

}

void Chumohuaban::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);                                //创建一个画笔
    QPen pen;
    pen.setColor(Qt::red);
     pen.setWidth(1);
     painter.setPen(pen);
     painter.drawPoint(xx,yy);

}
Chumohuaban::~Chumohuaban()
{

}

*/
class Yejjingpingd : public QDialog
{
    Q_OBJECT

public:
    Yejjingpingd(QWidget *parent = 0);
    void mousePressEvent(QMouseEvent *event);
    int count;
    int luognagflag;
    ~Yejjingpingd();

protected:
    void paintEvent(QPaintEvent *event);
};


class TmpDialog : public QDialog
{
    Q_OBJECT
 public:
     TmpDialog(QWidget *parent = 0);
    ~TmpDialog();
     QLabel * settmp ;
     QPushButton * surebutn ;
     QPushButton * errorbutn ;
     QPushButton * calbutn ;
     int item;
private slots:
     void sure();
     void error();
     void clatouch();
};

class TmpDialog1 : public QDialog
{
    Q_OBJECT
 public:
     TmpDialog1(QWidget *parent = 0);
    ~TmpDialog1();
     QLabel * settmp ;
     QPushButton * surebutn ;
     QPushButton * errorbutn ;
     int item;
private slots:
     void sure1();
     void error1();
};

#if 0
class PingReadThread : public QThread
{
    Q_OBJECT
public:
    explicit PingReadThread(QObject *parent = 0);
    int icmp_unpack(char* buf, int len);
    void stop();
   
signals:
    void readSignal(const QString data);

public slots:

protected:
    void run();

private:
   bool alive;
};

class PingSendThread : public QThread
{
    Q_OBJECT
public:
    explicit PingSendThread(QObject *parent = 0);
    
    void stop();
   
signals:

public slots:

protected:
    void run();

private:
   bool alive;
};



class PingTool : public QDialog
{
    Q_OBJECT

public:
	PingTool(QWidget *parent = 0);
	~PingTool();

	QPushButton *start_bt;
	QPushButton *stop_bt;
	QPushButton *one_key_getip_bt;
	QPushButton *exit_bt;
	QPushButton *read_log_bt;
	QPushButton *set_log_path;

	QLineEdit *ip_edit;
	QLineEdit *timing_edit;
	QLineEdit *count_edit;
	QLineEdit *period_edit;
	QLineEdit *pack_size_edit;

	QLabel *send_data_label;
	QLabel *recv_data_label;
	QLabel *loss_data_label;
	QLabel *loss_percent_data_label;
	

	QLabel *start_time_data_label;
	QLabel *end_time_data_label;
	QLabel *total_time_data_label;
	QLabel *cur_time_data_label;


	QRadioButton    *timingRadioBut;
	QRadioButton    *rationRadioBut;
	
	QComboBox *unitCombo;
	QString log_path;
	QString tmp_unit;
	 QProcess *process;

	InputMethod *im;
	QPlainTextEdit *debug_edit;

	int mode;
	int timing;
	int cur_time;
	int unit;
	int count;
	int period;
	int size;

	PingSendThread *ping_send;
	PingReadThread *ping_read;
	QTimer      *tickTimer;
	QTimer      *barTimer;
	QProgressBar *pProgressBar;

private:
	
	
	bool check_ping_vaile();
	void debug_add_text(const char *str);
	void debug_add_text(QString str);
	void debug_add_warning(const char *str);
	bool ping_socket_init(void);


private slots:
	void start_ping_test();
	void exit_ping_test();
	void stop_ping_test();
	void one_key_getip();
	void ping_mode_timing();
	void ping_mode_ration();
	void read_ping_log();
	void pingreceiveData(const QString str);
	void createImConnect(QString ObjName);
	void auto_draw_bar(void);
	void setLogPath(void);
	void pingReadOut();
	void pingResult();

};

class SdSpeedTest : public QDialog
{
    Q_OBJECT
 public:
	SdSpeedTest(QWidget *parent = 0);
	~SdSpeedTest();

	QPushButton *start_bt;
	QPushButton *clear_bt;
	QPushButton *remove_bt;
	QPushButton *exit_bt;
	QPushButton *dest_path_bt;
	QPushButton *read_bt;

	QGroupBox 	*write_param_grpbox;
	QGroupBox 	*read_param_grpbox;
	QGroupBox 	*write_result_grpbox;
	QGroupBox 	*read_result_grpbox;
	QGroupBox   *bar_grpbox;

	QLabel *src_label;
	QLabel *dest_label;
	QLabel *filename_label;
	QLabel *filesize_label;
	
	QLabel *read_src_filesize_label;
	QLabel *read_dest_filesize_label;
	QLabel *read_time_label;
	QLabel *read_speed_label;

	QLabel *read_src_filesize_data_label;
	QLabel *read_dest_filesize_data_label;
	QLabel *read_time_data_label;
	QLabel *read_speed_data_label;

	QLabel *write_src_filesize_label;
	QLabel *write_dest_filesize_label;
	QLabel *write_time_label;
	QLabel *write_speed_label;

	QLabel *write_src_filesize_data_label;
	QLabel *write_dest_filesize_data_label;
	QLabel *write_time_data_label;
	QLabel *write_speed_data_label;

	QLineEdit *src_path_edit;
	QLineEdit *dest_path_edit;
	QLineEdit *filename_edit;
	QLineEdit *filesize_edit;
	QTextEdit *debug_edit;

	QString usb_sd_path;
	QString src_file_path;
	QString dest_file_path;
	QString dest_file_name;
	QString src_file_name;
	QString cmd_read;
	QString cmd_write;

	QProgressBar *pProgressBar;

	QScrollArea *psplitter; //一个可滚动区域

	float read_speed;
	float write_speed;
	float read_time;
	float write_time;
	long long src_file_size;
	long long dest_file_size;

	InputMethod *im;
	
	
private: 
	void debug_add_text(const char *str);
	void debug_add_text(QString str);
	bool check_valid(void);
	void sd_usb_read_test(void);
	void sd_usb_write_test(void);
	bool ping_socket_init(void);
	int rawsock;

private slots:
	void dialog_close();
	void open_file();
	void debug_edit_clear();
	void start_sd_usb_test();
	void createImConnect(QString ObjName);
	void remove_test_file(void);
};

#endif


class CeshiSettings : public JDialog
{
    Q_OBJECT
 public:
     CeshiSettings(QWidget *parent = 0);
    ~CeshiSettings();

     QCheckBox *yejinpingQla ;
     QCheckBox *louguangQla;
     QCheckBox *chumopingQla;
     QCheckBox *com34_485Qla;
     QCheckBox *com12Qla ;
     QCheckBox *usb_sdQla ;
     QCheckBox *wifiQla;
     QCheckBox *wangkaQla;
     QCheckBox *beefQla;
     QCheckBox *beiguangQla;
     QCheckBox *canQla;
   //  QCheckBox *musicQla;
     SerialPortReadThread    *m_pReadThread1;
     SerialPortReadThread    *m_pReadThread2;
     SerialPortReadThread    *m_pReadThread3;
     SerialPortReadThread    *m_pReadThread4;
     SerialPort *bpMySerialPort1;
     SerialPort *bpMySerialPort2 ;
     SerialPort *bpMySerialPort3;
     SerialPort *bpMySerialPort4 ;
     QTimer*comtimer1;
     QTimer*comtimer2;
     QTimer*comtimer3;
     QTimer*comtimer4;

     QPushButton *yejinpingBtn;
     QPushButton *louguangBtn;
     QPushButton *chumopingBtn;
     QPushButton *com34_485Btn;
     QPushButton *com12Btn;
     QPushButton *usb_sdBtn;
     QPushButton *wifiBtn;
     QPushButton *wangkaBtn;
     QPushButton *beefBtn;
     QPushButton *beiguangBtn;
     QPushButton *canBtn;
     QPushButton *deleBtn;
     QPushButton *cpuFullBtn;

     QDialog *cpu_dialog;
     QLabel *cpudatalaber;
     QProcess *process;
     QProcess *pro_uart_1234;
     QProcess *pro_uart_12;

     char *S;
     char *S1;
   //  QLineEdit *m_canreEdit ;

private slots:
     void yejinping();
     void louguang();
     void chumo();
     void com34_485();
     void com12();
     void usb_sd();
     void wifi();
     void wangka();
     void beef();
     void beiguang();
     void can();
     void deletool();
   //  void musicceshi();
     QString readSubQss();
     void receiveData1(const QString str);
     void receiveData2(const QString str);
     void receiveData3(const QString str);
     void receiveData4(const QString str);
     void comtimer1fun();
     void comtimer2fun();
     void comtimer3fun();
     void comtimer4fun();
     void cpufull();
     void cpu_close();
     void readOut();
     void uart_1234_result();
     void uart_12_result();

private:

signals:
   //  void wqceshiTestBtnClicked();

};


#endif // NET_GUI_H

